package interfaces.menu.joinGame.filters;

import java.util.ArrayList;
import java.util.Collection;

import settings.FilterSettings;

import fileHandling.language.options.Filters;

import interfaces.options.ComboBoxOptionWidget;
import interfaces.options.OptionWidget;
import interfaces.options.OptionWidgetFactory;
import interfaces.options.OptionsContainer;
import interfaces.options.TextEditorOptionWidget;

public class FiltersContent extends OptionsContainer {
	
	private Collection<Filter> filters;
	private OptionWidgetFactory factory;
	
	public FiltersContent(int width, int height) {
		super(width, height, 0, 0);
		
		filters = new ArrayList<Filter>();
		
		factory = new OptionWidgetFactory("filters.xml", null);
		
		ShowEmptyFilter emptyFilter = new ShowEmptyFilter((ComboBoxOptionWidget)createWidget(Filters.Show_empty));
		addFilter(emptyFilter);
		
		ShowFullFilter fullFilter = new ShowFullFilter((ComboBoxOptionWidget)createWidget(Filters.Show_full));
		addFilter(fullFilter);
		
		addPlayersFilter(Filters.Min_Players, true);
		addPlayersFilter(Filters.Max_Players, false);
		
		MaxPingFilter pingFilter = new MaxPingFilter((TextEditorOptionWidget)createWidget(Filters.Max_Ping));
		addFilter(pingFilter);
		
		GameModeFilter modeFilter = new GameModeFilter((ComboBoxOptionWidget)createWidget(Filters.Game_Mode));
		addFilter(modeFilter);
		
		BotsFilter botsFilter = new BotsFilter((ComboBoxOptionWidget)createWidget(Filters.Enable_Bots));
		addFilter(botsFilter);
		
		FriendlyFireFilter friendlyFireFilter = new FriendlyFireFilter((ComboBoxOptionWidget)createWidget(Filters.Friendly_Fire));
		addFilter(friendlyFireFilter);
		
		layout();
	}
	
	private void addPlayersFilter(Filters f, boolean min) {
		TextEditorOptionWidget widget = (TextEditorOptionWidget)createWidget(f);
		PlayersFilter filter = new PlayersFilter(widget, min);
		addFilter(filter);
	}
	
	private void addFilter(Filter filter) {
		filters.add(filter);
		addOption(filter.getOptionWidget());
	}
	
	private OptionWidget createWidget(Filters f) {
		return factory.createWidget(f, FilterSettings.get().getValueOf(f));
	}
	
	public Collection<Filter> getFilters() { return filters; }
}